package com.xxxy.dongyexuan.service.impl;

import com.xxxy.dongyexuan.mapper.IOrderMapper;
import com.xxxy.dongyexuan.mapper.IReservationMapper;
import com.xxxy.dongyexuan.mapper.IUserMapper;
import com.xxxy.dongyexuan.po.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduleService {

    @Autowired
    private PayService payService;

    @Autowired
    private IOrderMapper orderMapper;

    @Autowired
    private IReservationMapper reservationMapper;

    @Scheduled(fixedDelay = 5000)
    public void queryUnknownOrder() {

        List<Order> orderList = orderMapper.findUnKnownOrderAll();

        // 循环查询订单状态并更新
        orderList.forEach(order -> {

            if (order.getQueryCount() > 6) {
                orderMapper.deleteById(order.getOrderId());
                // 同步删除预约订单
                reservationMapper.deleteLog(order.getRid());
            } else {
                payService.queryOrder(order);
            }
        });
    }

}
